package com.shuhua.taskServer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shuhua.pojo.entity.DirOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;

@Mapper
public interface DirOrderMapper extends BaseMapper<DirOrder> {
    @Select("SELECT d.*, t.*, c.username as craftsman_username, c.phone as craftsman_phone, c.real_name as craftsman_real_name, c.department as craftsman_department, c.station as craftsman_station, c.avatar as craftsman_avatar FROM dirorder d LEFT JOIN task t ON d.task_id = t.task_id LEFT JOIN craftsman c ON d.craftsman_id = c.id WHERE d.admin_id = #{adminId} AND d.task_id = #{taskId} AND d.craftsman_id = #{craftsmanId} LIMIT 1")
    Map<String, Object> selectDirOrderWithTask(@Param("adminId") Long adminId, @Param("taskId") Long taskId, @Param("craftsmanId") Long craftsmanId);

    @Select("SELECT d.*, t.*, c.username as craftsman_username, c.phone as craftsman_phone, c.real_name as craftsman_real_name, c.department as craftsman_department, c.station as craftsman_station, c.avatar as craftsman_avatar FROM dirorder d LEFT JOIN task t ON d.task_id = t.task_id LEFT JOIN craftsman c ON d.craftsman_id = c.id")
    List<Map<String, Object>> selectAllDirOrderWithTask();

    @Select("SELECT d.*, t.*, c.username as craftsman_username, c.phone as craftsman_phone, c.real_name as craftsman_real_name, c.department as craftsman_department, c.station as craftsman_station, c.avatar as craftsman_avatar FROM dirorder d LEFT JOIN task t ON d.task_id = t.task_id LEFT JOIN craftsman c ON d.craftsman_id = c.id WHERE d.craftsman_id = #{craftsmanId}")
    List<Map<String, Object>> selectDirOrderWithTaskByCraftsmanId(@Param("craftsmanId") Long craftsmanId);
} 